home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- *
- * Copyright (c) 1994-1999 3Com Corporation or its subsidiaries.
- * All rights reserved.
- *
- * PROJECT: Pilot
- * FILE: Starter.c
- * AUTHOR: Roger Flores: May 20, 1997
- *
- * DECLARER: Starter
- *
- * DESCRIPTION:
- *
- *
- **********************************************************************/
- #include <Pilot.h>
- #include <ScrDriverNew.h>
- #include <SysEvtMgr.h>
- #include "StarterRsc.h"
-
-
-
- /***********************************************************************
- *
- * Entry Points
- *
- ***********************************************************************/
-
-
- /***********************************************************************
- *
- * Internal Structures
- *
- ***********************************************************************/
- typedef struct
- {
- Byte replaceme;
- } StarterPreferenceType;
-
- typedef struct
- {
- Byte replaceme;
- } StarterAppInfoType;
-
- typedef StarterAppInfoType* StarterAppInfoPtr;
-
-
- /***********************************************************************
- *
- * Global variables
- *
- ***********************************************************************/
- //static Boolean HideSecretRecords;
-
-
- /***********************************************************************
- *
- * Internal Constants
- *
- ***********************************************************************/
- #define appFileCreator 'strt'
- #define appVersionNum 0x01
- #define appPrefID 0x00
- #define appPrefVersionNum 0x01
-
-
- // Define the minimum OS version we support
- #define ourMinVersion sysMakeROMVersion(2,0,0,sysROMStageRelease,0)
-
-
- /***********************************************************************
- *
- * Internal Functions
- *
- ***********************************************************************/
-
-
- /***********************************************************************
- *
- * FUNCTION: RomVersionCompatible
- *
- * DESCRIPTION: This routine checks that a ROM version is meet your
- * minimum requirement.
- *
- * PARAMETERS: requiredVersion - minimum rom version required
- * (see sysFtrNumROMVersion in SystemMgr.h
- * for format)
- * launchFlags - flags that indicate if the application
- * UI is initialized.
- *
- * RETURNED: error code or zero if rom is compatible
- *
- * REVISION HISTORY:
- *
- ***********************************************************************/
- static Err RomVersionCompatible(DWord requiredVersion, Word launchFlags)
- {
- DWord romVersion;
-
- // See if we're on in minimum required version of the ROM or later.
- FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
- if (romVersion < requiredVersion)
- {
- if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
- (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
- {
- FrmAlert (RomIncompatibleAlert);
-
- // Pilot 1.0 will continuously relaunch this app unless we switch to
- // another safe one.
- if (romVersion < sysMakeROMVersion(2,0,0,sysROMStageRelease,0))
- AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
- }
-
- return (sysErrRomIncompatible);
- }
-
- return (0);
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: GetObjectPtr
- *
- * DESCRIPTION: This routine returns a pointer to an object in the current
- * form.
- *
- * PARAMETERS: formId - id of the form to display
- *
- * RETURNED: VoidPtr
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static VoidPtr GetObjectPtr(Word objectID)
- {
- FormPtr frmP;
-
-
- frmP = FrmGetActiveForm();
- return (FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID)));
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: MainFormInit
- *
- * DESCRIPTION: This routine initializes the MainForm form.
- *
- * PARAMETERS: frm - pointer to the MainForm form.
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static void MainFormInit(FormPtr frmP)
- {
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: MainFormDoCommand
- *
- * DESCRIPTION: This routine performs the menu command specified.
- *
- * PARAMETERS: command - menu item id
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Boolean MainFormDoCommand(Word command)
- {
- Boolean handled = false;
-
-
- switch (command)
- {
- case MainOptionsAboutStarterApp:
- MenuEraseStatus (0);
- AbtShowAbout (appFileCreator);
- handled = true;
- break;
-
- }
- return handled;
- }
-
- #define sysFtrNumDisplayDepth 7 // Display depth
- // Result is the "default" display depth for the screen.
- // This value is used by ScrDisplayMode when setting the default display depth.
-
- //-----------------------------------------------------------------------
- // FUNCTION: SetDefaultDepth
- // DESCRIPTION: Set the default depth for the system
- // PARAMETERS: New default depth, pass 1 or 2 for that depth.
- //-----------------------------------------------------------------------
- static Err SetDefaultDepth(DWord newDefaultDepth)
- {
- Err err = FtrSet(sysFtrCreator, sysFtrNumDisplayDepth, newDefaultDepth);
- if (!err)
- err = ScrDisplayMode(scrDisplayModeSetToDefaults, NULL, NULL, NULL, NULL);
- return err ;
- }
-
- /***********************************************************************
- *
- * FUNCTION: MainFormHandleEvent
- *
- * DESCRIPTION: This routine is the event handler for the
- * "MainForm" of this application.
- *
- * PARAMETERS: eventP - a pointer to an EventType structure
- *
- * RETURNED: true if the event has handle and should not be passed
- * to a higher level handler.
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Boolean MainFormHandleEvent(EventPtr eventP)
- {
- Boolean handled = false;
- FormPtr frmP;
-
-
- switch (eventP->eType)
- {
- case menuEvent:
- return MainFormDoCommand(eventP->data.menu.itemID);
-
- case frmOpenEvent:
- frmP = FrmGetActiveForm();
- MainFormInit( frmP);
- FrmDrawForm ( frmP);
- SetDefaultDepth(2);
- handled = true;
- break;
-
- default:
- break;
-
- }
-
- return handled;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppHandleEvent
- *
- * DESCRIPTION: This routine loads form resources and set the event
- * handler for the form loaded.
- *
- * PARAMETERS: event - a pointer to an EventType structure
- *
- * RETURNED: true if the event has handle and should not be passed
- * to a higher level handler.
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Boolean AppHandleEvent( EventPtr eventP)
- {
- Word formId;
- FormPtr frmP;
-
-
- if (eventP->eType == frmLoadEvent)
- {
- // Load the form resource.
- formId = eventP->data.frmLoad.formID;
- frmP = FrmInitForm(formId);
- FrmSetActiveForm(frmP);
-
- // Set the event handler for the form. The handler of the currently
- // active form is called by FrmHandleEvent each time is receives an
- // event.
- switch (formId)
- {
- case MainForm:
- FrmSetEventHandler(frmP, MainFormHandleEvent);
- break;
-
- default:
- // ErrFatalDisplay("Invalid Form Load Event");
- break;
-
- }
- return true;
- }
-
- return false;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppEventLoop
- *
- * DESCRIPTION: This routine is the event loop for the application.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static void AppEventLoop(void)
- {
- Word error;
- EventType event;
-
-
- do {
- EvtGetEvent(&event, evtWaitForever);
-
-
- if (! SysHandleEvent(&event))
- if (! MenuHandleEvent(0, &event, &error))
- if (! AppHandleEvent(&event))
- FrmDispatchEvent(&event);
-
- } while (event.eType != appStopEvent);
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppStart
- *
- * DESCRIPTION: Get the current application's preferences.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: Err value 0 if nothing went wrong
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Err AppStart(void)
- {
- StarterPreferenceType prefs;
- Word prefsSize;
-
-
- // Read the saved preferences / saved-state information.
- prefsSize = sizeof(StarterPreferenceType);
- if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs, &prefsSize, true) !=
- noPreferenceFound)
- {
- }
-
- return 0;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppStop
- *
- * DESCRIPTION: Save the current state of the application.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static void AppStop(void)
- {
- StarterPreferenceType prefs;
-
-
- // Write the saved preferences / saved-state information. This data
- // will be backed up during a HotSync.
- PrefSetAppPreferences (appFileCreator, appPrefID, appPrefVersionNum,
- &prefs, sizeof (prefs), true);
- }
-
-
-
- /***********************************************************************
- *
- * FUNCTION: StarterPilotMain
- *
- * DESCRIPTION: This is the main entry point for the application.
- * PARAMETERS: cmd - word value specifying the launch code.
- * cmdPB - pointer to a structure that is associated with the launch code.
- * launchFlags - word value providing extra information about the launch.
- *
- * RETURNED: Result of launch
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static DWord StarterPilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- Err error;
-
-
- error = RomVersionCompatible (ourMinVersion, launchFlags);
- if (error) return (error);
-
-
- switch (cmd)
- {
- case sysAppLaunchCmdNormalLaunch:
- error = AppStart();
- if (error)
- return error;
-
- FrmGotoForm(MainForm);
- AppEventLoop();
- AppStop();
- break;
-
- default:
- break;
-
- }
-
- return 0;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: PilotMain
- *
- * DESCRIPTION: This is the main entry point for the application.
- *
- * PARAMETERS: cmd - word value specifying the launch code.
- * cmdPB - pointer to a structure that is associated with the launch code.
- * launchFlags - word value providing extra information about the launch.
- * RETURNED: Result of launch
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- return StarterPilotMain(cmd, cmdPBP, launchFlags);
- }
-
-